// viewImagePlugin.js
import Vue from 'vue';
import ViewImage from './index.vue';

const ImagePreviewConstructor = Vue.extend(ViewImage);

let instance;
/**
 * @type {import('@/types/global').viewImage}
 */
const viewImage = function (url) {
  if (!instance) {
    instance = new ImagePreviewConstructor({
      el: document.createElement('div')
    });
    document.body.appendChild(instance.$el);
  }

  Vue.nextTick(() => {
    instance.show(url);
  });
};

export default {
  install(Vue) {
    Vue.prototype.$viewImage = viewImage;
  }
};
